package org.protester.base;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;

import org.protester.core.CommentContainer;

/**
 * Define uma classe base para criar tipos de conteudos web gerenciaveis
 * 
 * @author fernandojr.ifcg@live.com
 * 
 */
@MappedSuperclass
public abstract class Content extends EntityBase {

	@Column(nullable = false)
	private String title;

	@Column(nullable = false)
	private String description;

	@Column(name = "date_published")
	private Date datePublished;
	
	@OneToOne(cascade=CascadeType.PERSIST)
	CommentContainer commentContainer;

	// TODO comments, likes

	public Content() {
	}

	public Content(String title, String description) {
		this.title = title;
		this.description = description;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getDatePublished() {
		return datePublished;
	}

	public void setDatePublished(Date datePublished) {
		this.datePublished = datePublished;
	}

	public abstract String getContent();

	/**
	 * Verifica se o protesto esta publicado
	 * 
	 * @return true caso esteja (dataPublished != null); false caso contrario
	 */
	public boolean isPublished() {

		if (datePublished != null)
			return true;
		else
			return false;
	}

	@Override
	public String toString() {
		return "Content [title=" + title + ", description=" + description
				+ ", datePublished=" + datePublished + "]";
	}

}
